<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

 
	// ------------------------------------------------------------------------

	/**
	 * getUserInfo
	 *
	 * Create a admin URL based on the admin folder path mentioned in config file. Segments can be passed via the
	 * first parameter either as a string or an array.
	 *
	 * @access	public
	 * @param	string
	 * @return	string
	 */
        function getUserInfo($userId=NULL)
	{
		$CI 	=& get_instance();
		$mod 	= $CI->load->model('user_model');
		$conditions = array('users.id'=>$userId);
		$result = $CI->user_model->getUsers($conditions);
		if($result->num_rows()>0)
		{
			$data = $result->row();	
		} else {
			$data = '';
		}
		
		return $data;	
	}
    function getTotalMessages(){
        //get total messages
        $CI = & get_instance();
        $CI->load->model('messages_model');
        if(isset($CI->loggedInUser->id) == TRUE){
            $conditions_m = array('to_id' => $CI->loggedInUser->id);
            return $CI->messages_model->getTotalMessages($conditions_m);
        }
    }

    /* sang 19-09-2014*/
    function getNameSkillByString($string = null){
        //get total messages
        $CI = & get_instance();
        $CI->load->model('user_model');
        if(isset($CI->loggedInUser->id) == TRUE){
           return $CI->user_model->getNameSkillByString($string);
        }
    }

    function getUserScore($userId){
    	$CI = & get_instance();
        $CI->load->model('user_model');
        if(isset($CI->loggedInUser->id) == TRUE){
           return $CI->user_model->getUserScore($userId);
        }

    }

	
	function file_get_contents_curl($url) 
	{

		$ch = curl_init();
		
		curl_setopt($ch, CURLOPT_HEADER, 0);
		
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
		
		curl_setopt($ch, CURLOPT_URL, $url);
		
		$data = curl_exec($ch);
		
		curl_close($ch);
		
		return $data;
	}
    function getNumProjectByUser($userID = null){
        $CI = & get_instance();
        $CI->load->model('skills_model');
        $conditions = array('projects.creator_id' => $userID);
        $fields = array('projects.id');
        return $CI->skills_model->getProjects($conditions,$fields)->num_rows();
    }
    function getCountry($country_id = null){
        $CI = & get_instance();
        $CI->load->model('common_model');
        $conditions = array('id' => $country_id);
        return $CI->common_model->getCountries($conditions);
    }
    function getStatusWatchList($user_id = null,$dev_id = null){
        $CI = & get_instance();
        $CI->load->model('common_model');
        $conditions = array('user_watchlist.user_id' => $user_id,'user_watchlist.dev_id' => $dev_id);
        $fields = array('user_watchlist.id');

        $result = $CI->user_model->getWatchList($conditions,$fields);
        if($result->num_rows() > 0){
            return TRUE;
        }else{
            return FALSE;
        }
    }

    function randchar($string = 'abcdefghijklmnopqrstuvwxyz0123456789'){
		return $string{rand(0,strlen($string)-1)};
	}

    function randstring($minlength = 1,$maxlength = 10,$characters ='abcdefghijklmnopqrstuvwxyz0123456789'){
		$result = ' ';
		for($i = 0; $i <= 8; $i++){
			$result{$i} = randchar($characters);
		}
		return $result;
	}

	function randemail(){
		$extensions = array('com','net','org','biz','gov');
		$afterAcong = array('gmail','yahoo','applancer');
		shuffle($extensions);
		return randstring(5,15) . '@' . $afterAcong[mt_rand(0,sizeof($afterAcong) - 1)] . '.' .$extensions[mt_rand(0,sizeof($extensions) - 1)];
    }

    function generateRandomString($length = 8) {
        $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $randomString = '';
        for ($i = 0; $i < $length; $i++) {
            $randomString .= $characters[rand(0, strlen($characters) - 1)];
        }
        return $randomString;
    }
	
/* End of file users_helper.php */
/* Location: ./app/helpers/users_helper.php */
?>